#pragma once

#include "item_id.h"

namespace icache {

class avi_reader;

///this is the tag for an AVI frame (may be loaded from disc cache at program startup),
///obviously, it does not know appropriate avi_reader and can't load image when it's absent in cache
class avi_frame_id : public item_id
{
public: //item_id interface
	virtual bool equal(const item_id & i) const;
	virtual string name() const;
	virtual void serialize(std::ostream & o) const;
	virtual bool loadable() const { return false; }
	virtual void load(byte_image & im) const;
	virtual bool requestable() const { return false; }
	virtual void request() const;
	virtual bool cache_on_disc() const;
public:
	int frame_num;
	string avi_fullpath;
	int avi_duration;
	bool cache_on_disc_;
public:
	avi_frame_id(int n, string const & f, int d, bool cd) : frame_num(n), avi_fullpath(f), avi_duration(d), cache_on_disc_(cd) { }
	avi_frame_id(avi_reader const & r, int n);
	static item_id_sptr create(int n, string const & f, int d, bool cd)
		{ return item_id_sptr(new avi_frame_id(n, f, d, cd)); }
	static item_id_sptr create(avi_reader const & r, int n)
		{ return item_id_sptr(new avi_frame_id(r, n)); }
};

class avi_frame_request : public avi_frame_id
{
public: //item_id interface
	virtual bool requestable() const { return true; }
	virtual void request() const;
public:
	avi_reader & reader;
	nearby desired;
	int priority;
public:
	avi_frame_request(avi_reader & r, int n, nearby may_be_requested_later, int p) : 
		avi_frame_id(r, n), reader(r), desired(may_be_requested_later), priority(p) { }
	static item_id_sptr create(avi_reader & r, int n, nearby may_be_requested_later, int p)
		{ return item_id_sptr(new avi_frame_request(r, n, may_be_requested_later, p)); }
};

class avi_frame_id_deserializer : public icache::item_id_deserializer
{
public:
	virtual item_id_sptr parse(std::istream & i) const;
};

} //namespace icache
